package com.js.admin.mapper;

import com.js.admin.entity.BaseAppOrder;
import com.js.admin.entity.BaseDepart;
import com.js.admin.entity.BaseUser;
import com.js.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author： ygl
 * @date： 2018/11/06-14:40
 * @Description：
*/
public interface BaseDepartMapper extends BaseMapper<BaseDepart> {

    @Select("<script>select u.name,u.username,u.id,u.sex,u.description,u.depart_id from base_depart d inner join base_depart_user bdu " +
            "  on bdu.depart_id = d.id inner join  base_user u  on bdu.user_id = u.id" +
            "  where bdu.depart_id = #{departId}" +
            "  <when test='userName!=null and userName!=\"\"'> " +
            "   and title like CONCAT('%',#{userName},'%')" +
            "   and u.is_deleted = '0'" +
            "   and u.is_disabled = '0'" +
            "  </when>" +
            " </script>")
    List<BaseUser> selectDepartUsers(@Param("departId") String departId, @Param("userName") String userName);

    @Insert("insert into base_depart_user (id,user_id,depart_id,tenant_id) values (#{id},#{userId},#{departId},#{tenantId})")
    void deleteDepartUser(@Param("departId")String departId, @Param("userId") String userId);

    @Delete("delete from base_depart_user where depart_id = #{departId} and user_id = #{userId}")
    void insertDepartUser(@Param("id") String id, @Param("departId") String departId, @Param("userId") String userId,@Param("tenantId") String tenantId);

}